package com.zzyl.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "资源管理")
@RestController
@RequestMapping("/resource")
public class ResourceController {
    @Autowired
    private ResourceService resourceService;
    @PostMapping("/list")
    @ApiOperation(value = "资源列表", notes = "资源列表")
    @ApiImplicitParam(name = "postDto", value = "岗位DTO对象", required = true, dataType = "PostDto")
    @ApiOperationSupport(includeParameters = {"postDto.deptNo", "postDto.dataState", "postDto.postName", "postDto.remark"})
    public ResponseResult<List<ResourceVo>> resourceList(@RequestBody ResourceDto resourceDto) {
        List<ResourceVo> resourceList = resourceService.findResourceList(resourceDto);
        return ResponseResult.success(resourceList);
    }

    @PostMapping("/tree")
    @ApiOperation(value = "资源树形", notes = "资源树形")
    @ApiImplicitParam(name = "postDto", value = "岗位DTO对象", required = true, dataType = "PostDto")
    @ApiOperationSupport(includeParameters = {"postDto.deptNo", "postDto.dataState", "postDto.postName", "postDto.remark"})
    public ResponseResult<TreeVo> resourceTreeVo(@RequestBody ResourceDto resourceDto) {
        TreeVo treeVo = resourceService.resourceTreeVo(resourceDto);
        return ResponseResult.success(treeVo);
    }
    @PutMapping ()
    @ApiOperation(value = "资源添加", notes = "资源添加")
    @ApiImplicitParam(name = "postDto", value = "岗位DTO对象", required = true, dataType = "PostDto")
    @ApiOperationSupport(includeParameters = {"postDto.deptNo", "postDto.dataState", "postDto.postName", "postDto.remark"})
    public ResponseResult<ResourceVo> CreateResource(@RequestBody ResourceDto resourceDto) {
        resourceService.createResource(resourceDto);
        return ResponseResult.success();
    }
    @DeleteMapping ("{resourceNo}")
    @ApiOperation(value = "资源添加", notes = "资源添加")
    @ApiImplicitParam(name = "postDto", value = "岗位DTO对象", required = true, dataType = "PostDto")
    @ApiOperationSupport(includeParameters = {"postDto.deptNo", "postDto.dataState", "postDto.postName", "postDto.remark"})
    public ResponseResult<ResourceVo> deleteByPrimaryKey(@RequestBody ResourceDto resourceDto) {
        resourceService.deleteByPrimaryKey(resourceDto);
        return ResponseResult.success();
    }
}